package org.example.service;

import org.example.entity.User;
import org.example.mapper.IUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    @Autowired
    private IUserMapper userMapper;

    // 1. 根据用户编号与密码查询用户信息
    public User getUserByIdByPass(String userId, String password) {
        return userMapper.selectUserByIdAndPass(userId, password);
    }

    // 2. 根据用户编号查询用户表返回的行数
    public int getUserById(String userId) {
        return userMapper.selectUserByIdCount(userId);
    }

    // 3. 向用户表中添加一条记录
    public int saveUser(String userId, String password, String userName, Integer userSex) {
        User user = new User();
        user.setUserId(userId);
        user.setPassword(password);
        user.setUserName(userName);
        user.setUserSex(userSex);
        user.setDelTag(0); // 默认未删除
        return userMapper.insert(user);
    }
} 